package com.neuedu.javase.jdbc.dao;

import com.neuedu.dbutil.JDBCUtils;
import com.neuedu.javase.jdbc.entity.Register;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-10-13 12:13
 * 描述 :
 */
public class RegisterDao {

    public Register selectById(Integer id) throws SQLException, ClassNotFoundException {
        Connection conn = JDBCUtils.getConnection();
        String sql = "select * from register where id = ?";
        return JDBCUtils.selectOne(conn, Register.class  , sql,id);
    }


    /**
     * 查询集合
     * @param sql
     * @param params
     * @return
     */
    public List<Register> selectList(String sql , Object ... params) throws SQLException, ClassNotFoundException {
        Connection conn = JDBCUtils.getConnection();
        return JDBCUtils.selectList(conn, Register.class  , sql,params);
    }


    public List<Register> selectPage(  String sql , int current,int size,Object ... params) throws SQLException, ClassNotFoundException {
        Connection conn = JDBCUtils.getConnection();
        return JDBCUtils.selectPage(conn, Register.class  , sql,current,size ,params);
    }




    public long selectCount(String sql ,Object ... params) throws SQLException, ClassNotFoundException {
        Connection conn = JDBCUtils.getConnection();
        long total = JDBCUtils.selectTotal(conn, sql, params);
       return total;
    }



    public int insert(String sql, Object ... params) throws SQLException, ClassNotFoundException {
        Connection conn = JDBCUtils.getConnection();
        int update = JDBCUtils.update(conn, sql, params);
        return update;
    }


    public int update(String sql, Object ... params) throws SQLException, ClassNotFoundException {
        Connection conn = JDBCUtils.getConnection();
        int update = JDBCUtils.update(conn, sql, params);
        return update;
    }


    /**
     * 根据主键删除
     * @param id
     * @return
     */
    public int deleteById(int id) throws SQLException, ClassNotFoundException {
        Connection conn = JDBCUtils.getConnection();
        String sql =" DELETE  FROM register WHERE id = ? ";

        int delete = JDBCUtils.update(conn, sql, id);
        return delete;
    }



}
